/*****************************************************************************
 * This file is part of the Prolog Development Tool (PDT)
 * 
 * Author: Lukas Degener (among others) 
 * E-mail: degenerl@cs.uni-bonn.de
 * WWW: http://roots.iai.uni-bonn.de/research/pdt 
 * Copyright (C): 2004-2006, CS Dept. III, University of Bonn
 * 
 * All rights reserved. This program is  made available under the terms 
 * of the Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 * 
 * In addition, you may at your option use, modify and redistribute any
 * part of this program under the terms of the GNU Lesser General Public
 * License (LGPL), version 2.1 or, at your option, any later version of the
 * same license, as long as
 * 
 * 1) The program part in question does not depend, either directly or
 *   indirectly, on parts of the Eclipse framework and
 *   
 * 2) the program part in question does not include files that contain or
 *   are derived from third-party work and are therefor covered by special
 *   license agreements.
 *   
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *   
 * ad 1: A program part is said to "depend, either directly or indirectly,
 *   on parts of the Eclipse framework", if it cannot be compiled or cannot
 *   be run without the help or presence of some part of the Eclipse
 *   framework. All java classes in packages containing the "pdt" package
 *   fragment in their name fall into this category.
 *   
 * ad 2: "Third-party code" means any code that was originaly written as
 *   part of a project other than the PDT. Files that contain or are based on
 *   such code contain a notice telling you so, and telling you the
 *   particular conditions under which they may be used, modified and/or
 *   distributed.
 ****************************************************************************/

/*
 * HTMLWriter.java
 *
 * Created on 2. Januar 2002, 00:20
 */

package org.cs3.pl.doc;

import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
/**
 *
 * @author  windeln
 */
public class HTMLWriter {

    public String styleSheetPath = "";
	private Writer writer;
    
    /** Creates a new instance of HTMLWriter */
    public HTMLWriter(String styleSheetPath) {
        this.styleSheetPath = styleSheetPath;
    }
    
//    /**
//	 * @param string
//	 */
//	protected void openStream(OutputStream out) {
//    	writer = new OutputStreamWriter(out);
//	}

	protected void close() throws IOException {
    	writer.close();
	}
    
    void writeTableHead(String type, String name) throws IOException {
        write(
            "<!-- ========== " + type.toUpperCase() + " " + name.toUpperCase() + " =========== -->\n"+ 
            "<A NAME=\"" + type.toLowerCase() + "_" + name.toLowerCase() + "\"><!-- --></A>\n"+ 
            "<TABLE BORDER=\"0\" CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"100%\">\n"+ 
            "<TR BGCOLOR=\"#CCCCFF\" CLASS=\"TableHeadingColor\">\n"+ 
            "<TD COLSPAN=2><FONT SIZE=\"+1\">\n"+ 
            type + " " + name + "</FONT></TD>\n"+ 
            "</TR>\n");
    }

    void writeHeading(String heading, int num) throws IOException {
        write("<H" + num + "> " + heading + "</H" + num + ">\n");
    }
    
    void writeHeading(String heading) throws IOException {
        writeHeading(heading, 1);
    }
     
    void writeDefaultHeader(String title) throws IOException {
        write(
            "<HTML>\n" + 
            "<HEAD>\n" + 
            "<!-- Generated by prolog documentation (by Tobias Rho) on " + getCurrentTimeDate() + "-->\n" + 
            "<TITLE>\n" + 
            ": " + title + "\n" + 
            "</TITLE>\n" + 
            "<LINK REL =\"stylesheet\" TYPE=\"text/css\" HREF=\"" + styleSheetPath + "\" TITLE=\"Style\">\n" + 
            "</HEAD>\n" +
            "<BODY BGCOLOR=\"white\">\n");
    }
    
    
    void writeHead(String name) throws IOException {
        writeDefaultHeader(name);
    }        
    
    void writeTail() throws IOException {
        write("</BODY>\n"+
                    "</HTML>\n");
    }    
    
    protected void write(String str) throws IOException {
    	writer.write(str);
    }
    
    String getCurrentTimeDate() {
        GregorianCalendar c = new GregorianCalendar();
        SimpleDateFormat df = new SimpleDateFormat();
        return df.format(c.getTime());
    }

	/**
	 * @param metaDataWriter
	 */
	protected void setWriter(Writer metaDataWriter) {
		writer = metaDataWriter;
		
	}

}
